<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>文化剧场管理</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="icon" href="/favicon.ico">
<link rel="stylesheet" th:href="@{/resources/layui/css/layui.css}" media="all" />
<link rel="stylesheet" th:href="@{/resources/css/public.css}" media="all" />
<link rel="stylesheet" th:href="@{/resources/layui_ext/dtree/dtree.css}" media="all" />
<link rel="stylesheet" th:href="@{/resources/layui_ext/dtree/font/dtreefont.css}" media="all" />
</head>
<body class="childrenBody">
<!-- 查询条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;">
  <legend>查询条件</legend>
</fieldset>
<blockquote class="layui-elem-quote">
	<form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form layui-form-pane">
		<div class="layui-form-item">
		    <div class="layui-inline">
		      <label class="layui-form-label">素材名称</label>
		      <div class="layui-input-inline">
		        <input type="text" name="sourcesname"  autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-inline">
		      <label class="layui-form-label">开始时间</label>
		      <div class="layui-input-inline">
		         <input type="text" name="startTime" readonly="readonly"  id="startTime" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-inline">
		      <label class="layui-form-label">结束时间</label>
		      <div class="layui-input-inline">
		         <input type="text"  name="endTime" readonly="readonly"  id="endTime"  autocomplete="off" class="layui-input">
		      </div>
		    </div>
		  </div>
		  <div class="layui-form-item">
		  	 <div class="layui-input-block" style="text-align: center;">
		       	<button type="button" class="layui-btn" lay-submit="" lay-filter="doSearch"><span class="layui-icon layui-icon-search"></span>查询</button>
      			<button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
		      </div>
		  </div>
	</form>
</blockquote>
<!-- 查询条件结束-->


<!-- 数据表格开始 -->
<div>
	<table class="layui-hide" id="SourcesTable" lay-filter="SourcesTable"></table>
	<div id="SourcesToolBar" style="display: none;">
		<button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-1"></span>添加素材</button>
		<button type="button" lay-event="batchUpdate" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-1"></span>审核素材</button>
		<button type="button" lay-event="batchOffupdate" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-1"></span>取消审核</button>
	<!--	<button type="button" lay-event="batchpublish" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-1"></span>发布</button>  -->
	</div>
	
	<div id="SourcesRowBar" style="display: none;">
		<button type="button" lay-event="update" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-edit"></span>更新</button>
		<button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger"><span class="layui-icon layui-icon-delete"></span>删除</button>
	</div>
</div>

<!-- 数据表格结束 -->

<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding: 5px" id="addOrUpdateDiv">
	<form action="" method="post" class="layui-form layui-form-pane" id="dataFrm" lay-filter="dataFrm">
		<div class="layui-col-md12 layui-col-xs12">
			<div class="layui-row layui-col-space10">
				<div class="layui-col-md9 layui-col-xs7">
					<div class="layui-form-item">
						<label class="layui-form-label">素材类型</label>
						<div class="layui-input-block" id="sourcestype">
							 <input type="radio"  name="sourcestype" value="图片" title="图片" lay-filter="aaa" checked/>
           					 <input type="radio"  name="sourcestype" value="视频" title="视频" lay-filter="aaa"/>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">素材名称</label>
						<div class="layui-input-block">
							 <input type="hidden" name="id">
							<input type="text" class="layui-input"  autocomplete="off" name="sourcesname" lay-verify="required" placeholder="请输入名称">
						</div>
					</div>
					<div class="layui-form-item aa">
						<label class="layui-form-label">网点设备清单</label>
						<div class="layui-input-block">
		                    <ul id="permissionTree" class="dtree" data-id="0" ></ul>
						</div>
					</div>
					<div class="layui-form-item  bb">
						<label class="layui-form-label">设备编号</label>
						<div class="layui-input-block">
		                    <input type="text" class="layui-input" autocomplete="off" maxlength="120" id="bankordevice" name="bankordevice" lay-verify="required" >
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">播放区间</label>
		    			<div class="layui-input-block">
		    			 	 <input type="hidden" name="id">
		                     <input type="text"  name="timerange" readonly="readonly"  id="timerange" lay-verify="required"  autocomplete="off" class="layui-input">
		                </div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">素材描述</label>
						<div class="layui-input-block">
							 <input type="hidden" name="id">
							<input type="text" class="layui-input"  autocomplete="off" name="sourcescontent" lay-verify="required" placeholder="请输入描述内容">
						</div>
					</div>
					<div class="layui-form-item cc">
						<label class="layui-form-label">网点主键集合</label>
						<div class="layui-input-block">
							<input type="text" class="layui-input" autocomplete="off" maxlength="120" name="listid"  >
						</div>
					</div>
					<div class="layui-form-item videos" >
        			    <label class="layui-form-label" style="height: 100px; line-height: 117px">上传视频</label>
        		    	 <div class=" layui-upload-drag" id="videoQ" name="videoQ" style="border-left: 0px;" type="video">
            	    	 	<i class="layui-icon">&#xe654;</i>
            	    		 <p>点击上传</p>
            				 <video id="videoS"  src="" style="position: absolute;height: 100px;width: 137px;margin: -60px auto auto -60px;"/>
       		 	         </div>
       		 	         <input type="hidden" name="video" id="video" >
     		      </div>
					
				</div>
				<div class="layui-col-md3 layui-col-xs5 images">
					<div class="layui-upload-list thumbBox mag0 magt3">
						<input type="hidden" name="sources" id="sources" value="images/defaultgoodsimg.png">
						<img class="layui-upload-img thumbImg" th:src="@{/file/showImageByPath?path=images/defaultgoodsimg.png}">
					</div>
					<h3 style="text-align:center; color: red">《图片》</h3>
				</div>
				<div class="layui-col-md3 layui-col-xs5 backgroundimages">
					<div class="layui-upload-list thumbBoxQ mag0 magt3">
						<input type="hidden" name="backgroundimages" id="backgroundimages" value="images/defaultgoodsimg.png">
						<img class="layui-upload-img thumbImgQ" th:src="@{/file/showImageByPath?path=images/defaultgoodsimg.png}">
					</div>
					<h3 style="text-align:center; color: red">《背景图》</h3>
				</div>
			</div>
			<div class="layui-form-item">
			    <div class="layui-input-block" style="text-align: center;">
			      	<button type="button" class="layui-btn" lay-submit="" lay-filter="doSubmit" id="doSubmit" ><span class="layui-icon layui-icon-add-1"></span>提交</button>
	      			<button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
			     </div>
 	   		</div>
		</div>
	</form>
</div>
<!-- 添加和修改的弹出层结束 -->



<script type="text/javascript" th:src="@{/resources/layui/layui.js}"></script>
<script type="text/javascript">
var tableIns;
var context_path = "[[@{/}]]";
layui.extend({
    dtree: '/resources/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
  }).use(['jquery','dtree','form','table','layer','upload','laydate'],function(){
		var $=layui.jquery;
		var form=layui.form;
		var table=layui.table;
		var layer=layui.layer;
		var upload=layui.upload;
		var laydate=layui.laydate;
		var dtree = layui.dtree;
		//渲染时间选择器
		laydate.render({
			elem:'#startTime',
			type:'datetime'
		});
		laydate.render({
			elem:'#endTime',
			type:'datetime'
		});
		laydate.render({
			elem:'#timerange',
			type:'datetime',
			 range: '~'
		});
		//加载 数据
		 tableIns=table.render({
			 elem: '#SourcesTable'
		    ,url:context_path+'Sources/loadAllSources'
		    ,toolbar: '#SourcesToolBar' //开启头部工具栏，并为其绑定左侧模板
		    ,title: '素材数据表'
		    ,height:'full-280'
		    ,page: true
		    ,cols: [ [
		      {type: 'checkbox', fixed: 'left'}
		      ,{field:'id', title:'ID',align:'center' ,width:'100'}
		      ,{field:'sourcesname', title:'素材名称',align:'center',width:'100'}
		      ,{field:'sources', title:'素材',align:'center',width:'200', templet:function(d){
		      		if(d.sourcestype == "图片" && d.sources!='images/defaultgoodsimg.png'){
		      			return '<img width=40 height=40 src=/file/showImageByPath?path='+d.sources+ ' />';
		      		}else if(d.sourcestype == "视频" && d.sources!='images/defaultgoodsimg.png') {
		      			return '<video width=40 height=40 src='+context_path+'upload/'+ d.sources+ ' />';
		      		}else{
		      		    return '';
		      		}
		      }}
		      ,{field:'sourcestype', title:'素材类别',align:'center',width:'100'}
		      ,{field:'backgroundimages', title:'背景图片',align:'center',width:'150', templet:function(d){
		    	  if(d.sourcestype == "图片" || d.backgroundimages=='images/defaultgoodsimg.png'){
		      			return '';
		      		}else {
		      			return '<img width=40 height=40 src=/file/showImageByPath?path='+d.backgroundimages+ ' />';
		      		}
		      }}
		      ,{field:'banknbr', title:'网点编号',align:'center',width:'100'}
		      ,{field:'terminalno', title:'设备编号',align:'center',width:'100'}
		      ,{field:'available', title:'是否审批',align:'center',width:'100',templet:function(d){
		    	  return d.available==1?'<font color=blue>已审批</font>':'<font color=red>未审批</font>';
		      }}
		      ,{field:'sourcestime', title:'上传时间',align:'center',width:'200'}
		      ,{field:'timerange', title:'时间区间',align:'center',width:'200'}
		      ,{field:'sourcescontent', title:'素材描述',align:'center',width:'100'}
		      ,{field:'bankordevice', title:'网点设备集合',align:'center',width:'100'}
		      ,{field:'listid', title:'网点id集合',align:'center',width:'100'}
		      ,{fixed: 'right', title:'操作', toolbar: '#SourcesRowBar',align:'center',width:'200'}
		    ] ]
		      ,done: function(res, curr, count){ //处理删除某一页最后一条数据的BUG
			        if(res.data.length==0&&curr!=1){
			        	tableIns.reload({
			        		page:{
			        			curr:(curr-1)
			        		}
			        	});
			        }
			    }
		});
		
		//视频和图片上传模式切换切换
		 form.on('radio(aaa)', function (data) {
 
                if ($('#sourcestype input[name="sourcestype"]:checked ').val() == "视频") {
                    $(".videos").show();
                    $(".backgroundimages").show();
                     $(".images").hide();
                }
                else {
                    $(".images").show();
                    $(".videos").hide();
                    $(".backgroundimages").hide();
                }
                form.render();
            });
		
		//模糊查询
		form.on("submit(doSearch)",function(data){
			tableIns.reload({
				where:data.field,
				page:{
					curr:1
				}
			});
			return false;
		});
		
		//监听工具条的事件
		table.on("toolbar(SourcesTable)",function(obj){
			 switch(obj.event){
			    case 'add':
			     openAddLayer();
			    break;
			    case 'batchDelete':
			    	batchDelete();
			    break;
			    case 'batchUpdate':
				  	 batchUpdate();    //批量审核
			    break;
			      case 'batchOffupdate':
       				  batchOffupdate();  //取消审核
     		    break;
			      case 'batchpublish':
       				  batchpublish();  //发布
     		    break;
			  };
		});
		
		//监听行工具条的事件
		table.on("tool(SourcesTable)",function(obj){
			  var data = obj.data; //获得当前行数据
			 switch(obj.event){
			    case 'update':
			   		openUpdateGoodsLayer(data);
			    break;
			    case 'delete':
			   		deleteGoods(data);
			    break;
			  };
		});
		
		var mainIndex;
		var url;
		//打开添加的弹出层
		function openAddLayer(){
			mainIndex=layer.open({
				type:1,
				content:$("#addOrUpdateDiv"),
				area:['800px','600px'],
				title:'添加素材',
				success:function(){
					$("#dataFrm")[0].reset();
					url=context_path+"Sources/addSources";
					
					//根据角色ID请求权限和菜单tree的json数据
					 dtree.render({
						elem: "#permissionTree",
						url: context_path+'Sources/loadTreeJson',
						dataStyle: "layuiStyle",  //使用layui风格的数据格式
						dataFormat: "list",  //配置data的风格为list
						response:{message:"msg",statusCode:0},  //修改response中返回数据的定义
						checkbar: true,      //开启复选框
						checkbarType: "self", // 默认就是all，其他的值为： no-all  p-casc   self  only
					});
					dtree.on('chooseDone("permissionTree")', function(obj){
					  var param = obj.checkbarParams;
					  var ids="";
						$.each(param,function(index,item){
							if(index==0){
								ids+=""+item.context;
							}else{
								ids+=","+item.context;
							}
						})
						//给设备框赋值
					   $("#bankordevice").val(ids);
					});
					
					//默认选中
					 if ($('#sourcestype input[name="sourcestype"]:checked ').val() == "视频") {
                       	   $(".videos").show();
                       	   $(".backgroundimages").show();
                       	   $(".images").hide();
                    }else {
                  		   $(".images").show();
                 		   $(".videos").hide();
                 		   $(".backgroundimages").hide();
                    }
				 	
					//设置默认图片
					$(".thumbImg").attr("src",'/resources/images/defaultgoodsimg.png');
					$(".thumbImgQ").attr("src",'/resources/images/defaultgoodsimg.png');
				//	$(".thumbImg").attr("src",'/file/showImageByPath?path=images/defaultgoodsimg.png');
				//	$(".thumbImgQ").attr("src",'/file/showImageByPath?path=images/defaultgoodsimg.png');
					$("#sources").val('images/defaultgoodsimg.png');
					$(".cc").hide();
				}
			});
		}
		
		//打开修改的弹出层
		function openUpdateGoodsLayer(data){
			//得到选中行
			var available=data.available;
			if(available==0){
				
			mainIndex=layer.open({
				type:1,
				content:$("#addOrUpdateDiv"),
				area:['800px','600px'],
				title:'修改商品',
				success:function(){
					$("#dataFrm")[0].reset();
					//装载新的数据
					form.val("dataFrm",data);
					url=context_path+"Sources/updateSources";
					
					//根据角色ID请求权限和菜单tree的json数据
					dtree.render({
						elem: "#permissionTree",
						url: context_path+'Sources/loadTreeJson',
						dataStyle: "layuiStyle",  //使用layui风格的数据格式
						dataFormat: "list",  //配置data的风格为list
						response:{message:"msg",statusCode:0},  //修改response中返回数据的定义
						checkbar: true,  
						checkbarType: "self" // 默认就是all，其他的值为： no-all  p-casc   self  only
						
					});
					 $(".aa").hide();  //网点机构隐藏
					 $(".bb").hide();  //设备编号隐藏
					 $(".cc").hide();
					
					//默认选中
					 if ($('#sourcestype input[name="sourcestype"]:checked ').val() == "视频") {
                       	   $(".videos").show();
                       	   $(".backgroundimages").show();
                       	   $(".images").hide();
                       	   $(".thumbImgQ").attr("src",'/file/showImageByPath?path='+data.backgroundimages);
                       	   $('#videoS').attr('src',context_path+'upload/'+data.sources);
                    }else {
                  		   $(".images").show();
                 		   $(".videos").hide();
                 		   $(".backgroundimages").hide();
                 		   $(".thumbImg").attr("src",'/file/showImageByPath?path='+data.sources);
                    }
					
					
					
				}
			});
			
			}else{
				layer.msg("【已审批】数据不管操作！")
			}
		}
		
		form.on("submit(doSubmit)",function(data){
			  $.post(url,data.field,function(res){
					if(res.code==200){
						tableIns.reload();
					}
						layer.msg(res.msg);
						layer.close(mainIndex);
					}) 
			return false;
		});
		
		//文件上传
	    upload.render({
	        elem: '.thumbBox',
	        url: context_path+'file/uploadFile',
	        acceptMime:'image/*',
	        field:'mf',
	        method : "post",  //此处是为了演示之用，实际使用中请将此删除，默认用post方式提交
	        done: function(res, index, upload){
	        	var path=res.path;
	            $('.thumbImg').attr('src','/file/showImageByPath?path='+path);
	            $('.thumbBox').css("background","#fff");
	            $("#sources").val(path);//给隐藏域赋值
	        }
	    });
	    
	    //背景图片上传
	    upload.render({
	        elem: '.thumbBoxQ',
	        url: context_path+'file/uploadFile',
	        acceptMime:'image/*',
	        field:'mf',
	        method : "post",  //此处是为了演示之用，实际使用中请将此删除，默认用post方式提交
	        done: function(res, index, upload){
	        	var path=res.path;
	            $('.thumbImgQ').attr('src','/file/showImageByPath?path='+path);
	            $('.thumbBoxQ').css("background","#fff");
	            $("#backgroundimages").val(path);//给隐藏域赋值
	        }
	    });
	    
	    //视频上传
	    upload.render({
	        elem: '#videoQ',
	        url: context_path+'file/uploadVideo',
	        accept: 'video',
	        field:'mf',
	        method : "post",  
	        done: function(res, index, upload){
	        	var path=res.path;
	        //	alert("path:"+path);
              layer.alert("上传成功",{offset:['200px','450px'],icon:6});
	           $('#videoS').attr('src',context_path+'upload/'+path);
	           $('#videoS').css("background","#fff");
	           $("#sources").val(path);//给隐藏域赋值
	        }
	    });
	    
	    
	    //批量审批
		function  batchUpdate(){
			//得到选中行
			var checkStatus = table.checkStatus('SourcesTable');
			var dataLength=checkStatus.data.length;   //获取选中行的条数
			if(dataLength>0){
				var dataArray=checkStatus.data;
				var a=dataArray[0];               //拿出数组的第一条数据
				var terminalno = a.terminalno;          //获取此数据的 设备编号
				var available = a.available;          //获取此数据的 审批状态
				var jin =0 ;
				if(available == 1){
					layer.msg("选中的有【已审批】的数据，请重新选择")
				}else{
					for(var i in dataArray){
					  var ter = dataArray[i].terminalno;
						if(terminalno != ter){
							layer.msg("请选择一种【设备号】进行操作！");
							jin = 1;
							break;
						}
					}
					if(jin == 0){
						layer.confirm('确定要审批通过吗?', {icon: 3, title:'提示'}, function(index){
								var data=checkStatus.data; //获取选中行的数据
								var ids="";
								$.each(data,function(index,item){
									if(index==0){
										ids+="ids="+item.id;
									}else{
										ids+="&ids="+item.id;
									}
								})
								$.post(context_path+"Sources/batchUpdateSourcesList",ids,function(res){
									if(res.code==200){
										tableIns.reload();
									}
									layer.msg(res.msg);
								})	
							   layer.close(index);
							});
					}	
					
				}
			}else {
				layer.msg("请选中操作行")
			}
		}
		
		//取消审核
		function  batchOffupdate(){
			//得到选中行
			var checkStatus = table.checkStatus('SourcesTable');
			var dataLength=checkStatus.data.length;
			if(dataLength>0){
				var dataArray=checkStatus.data;
				var a=dataArray[0];               //拿出数组的第一条数据
				var terminalno = a.terminalno;          //获取此数据的 设备编号
				var available = a.available;          //获取此数据的 审批状态
				var jin =0 ;
				if(available == 0){
					layer.msg("选中的有【未审批】的数据，请重新选择")
				}else{
					for(var i in dataArray){
					  var ter = dataArray[i].terminalno;
						if(terminalno != ter){
							layer.msg("请选择一种【设备号】进行操作！");
							jin = 1;
							break;
						}
					}
					if(jin == 0){
						layer.confirm('确定要取消审批吗?', {icon: 3, title:'提示'}, function(index){
						var data=checkStatus.data; //获取选中行的数据
						var ids="";
						$.each(data,function(index,item){
							if(index==0){
								ids+="ids="+item.id;
							}else{
								ids+="&ids="+item.id;
							}
						})
						$.post(context_path+"Sources/batchOffupdateSourcesList",ids,function(res){
							if(res.code==200){
								tableIns.reload();
							}
							layer.msg(res.msg);
						})	
					   layer.close(index);
					});
					}	
				}
			}else {
				layer.msg("请选中操作行")
			}
			
		}
	    
	    //批量发布
		function  batchpublish(){
			//得到选中行
			var checkStatus = table.checkStatus('SourcesTable');
			var dataLength=checkStatus.data.length;
			if(dataLength>0 && dataLength <=5){
				layer.confirm('确定要发布吗?', {icon: 3, title:'提示'}, function(index){
						var data=checkStatus.data; //获取选中行的数据
						var ids="";
						$.each(data,function(index,item){
							if(index==0){
								ids+="ids="+item.id;
							}else{
								ids+="&ids="+item.id;
							}
						})
						$.post(context_path+"Sources/batchPublish",ids,function(res){
							if(res.code==200){
								tableIns.reload();
							}
							layer.msg(res.msg);
						})	
					   layer.close(index);
					});
				
			}else if(dataLength >5){
				layer.msg("最多选择5条发布的数据")
			}else {
				layer.msg("请选中操作行")
			}
		}
		
		//删除
		function deleteGoods(data){
		//得到选中行
		 var available=data.available;
		 if(available==0){
			layer.confirm('你确定要删除【'+data.sourcesname+'】这个素材吗?', {icon: 3, title:'提示'}, function(index){
				$.post(context_path+"Sources/deleteSources",{id:data.id,listid:data.listid,sources:data.sources,backgroundimages:data.backgroundimages},function(res){
					if(res.code==200){
						tableIns.reload();
					}
					layer.msg(res.msg);
				})	
			   layer.close(index);
			});
		  }else{
				layer.msg("【已审批】数据不管操作！");
	     	}		
		}
		
  });
</script>

</body>
</html>